/* Copyright (c) 2013, BNRC, Beijing University of Posts and Telecommunications 
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   * Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *   * Neither the name of the Ericsson Research nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: Tong Zhou
 */

#ifndef OPENFLOW_BNRC_EXT_H
#define OPENFLOW_BNRC_EXT_H 1

#include "openflow/openflow.h"

#define BNRC_OUI_STR "002330"
#define NETPDL_MAX_LEN 8192


/* The following vendor extensions, proposed by BNRC, are not yet
 * ready for standardization (and may never be), so they are not included in
 * openflow.h. */

#define BNRC_VENDOR_ID 0x424e5243

enum ofp_exp_bnrc_msg_type { /* BNRC configuration commands */
    /* Queue Commands */
    OFP_EXP_QUEUE_MOD,  /* Add and/or modify */
    OFP_EXP_PROTO_TABLE_MOD,
    //TODO::new type can add here
    
    MAX_NUM_OF_BNRC_EXP_TYPE
};


struct bnrc_header {
    struct ofp_header header;
    uint32_t vendor;            /* NX_VENDOR_ID. */
    uint32_t subtype;           /* One of OFPT_BNRC_EXT_* above. */
};
OFP_ASSERT(sizeof(struct bnrc_header) == 16);

struct bxt_proto_table_mod {
    struct bnrc_header bnh;
    uint8_t command;                /* There are three commands:add new table, modify table, delete table.
                                     * Currently, Format of Delete Table are not added.
                                     */
    uint8_t pad[7];
	uint8_t data[NETPDL_MAX_LEN];				/* Store the NetPDL description. */
};
OFP_ASSERT(sizeof(struct bxt_proto_table_mod) == 24 + 8192);

/* Generic Encapsulation */
struct ofp_action_encap {
    uint16_t type;
    uint16_t len;
    uint16_t proto_id;
	uint16_t data_len;
    uint8_t data[0];
};
OFP_ASSERT(sizeof(struct ofp_action_encap) == 8);

/* Generic Decapsulation */
struct ofp_action_decap {
    uint16_t type;
    uint16_t len;
    uint16_t proto_id;
	uint16_t payload_proto_id;
};
OFP_ASSERT(sizeof(struct ofp_action_decap) == 8);

struct ofp_action_mod_any_field {
    uint16_t type;
    uint16_t len;
    uint32_t field_id;
	uint16_t data_len;
    uint8_t mask_seq;
	uint8_t pad[5];
    uint8_t data[0];
};
OFP_ASSERT(sizeof(struct ofp_action_mod_any_field) == 16);

struct ofp_queue_configure{
    char		name[8];
    uint32_t	type;
    uint32_t 	port;
    uint32_t 	queue_id;
    uint32_t 	parent_id;
    uint8_t 	command;
    uint8_t 	pad[3];
    uint32_t 	num;
    uint8_t  	data[0];
};
OFP_ASSERT(sizeof(struct ofp_queue_configure) == 32);

struct ofp_queue_param_list{
    char 		param_name[8];
    uint32_t	data;
	char		unint[8];
	uint8_t     pad[4];
};
OFP_ASSERT(sizeof(struct ofp_queue_param_list) == 24);

enum ofp_queue_type {
	OFPQT_QDISC,
	OFPQT_CLASS
};

enum ofp_queue_command {
	OFPQC_ADD,
	OFPQC_DEL,
	OFPQC_MOD
};

enum ofp_proto_table_mod_command {
    OFPTMT_ADD,
	OFPTMT_DELETE
};

struct ofp_msg_queue_mod {
    struct bnrc_header header;
    struct ofp_queue_configure queue;
};
OFP_ASSERT(sizeof(struct ofp_msg_queue_mod) == 48);


#endif /* openflow/bnrc-ext.h */
